package lifeOfAFish.scenegraph;

import javax.media.opengl.GL;

public class sgLightFactory {

	// a list representing the which light sources are already in use
	protected static int[] m_lights = {0,0,0,0,0,0,0,0,0,0};
	protected static final int MaxLights = 8;
	
	/**
	 * create a new light source
	 */
	public static sgLight newLight() {
		
		// find the next available source
		int index = 0;
		for(; m_lights[index] == 1 && index < MaxLights; index++);
		m_lights[index] = 1;
		
		sgGlobals.gl.glEnable(GL.GL_LIGHT0+index);
		return new sgLight(GL.GL_LIGHT0+index);
	}
	
	/**
	 * To be called from light objects when they are being destroyed
	 */
	protected static void freeLight(int index)
	{
		index -= GL.GL_LIGHT0;
		if (index < MaxLights && index > 0)
			m_lights[index] = 0;
	}
	
}
